package com.teach.basic.controller;

import com.teach.basic.model.dto.FoodDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.teach.basic.service.impl.FoodsServiceImpl;
import com.teach.basic.model.po.Foods;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 美食表 前端控制器
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-02-18
 */
@RestController
@RequestMapping("/foods")
public class FoodsController {
    @Autowired
    private FoodsServiceImpl serviceFoods;

    @RequestMapping("/index")
    public String fun(HttpServletRequest request,HttpServletResponse response){
        return "ok";
    }
    @RequestMapping("/list")
    public List<Foods> getList(){
        return serviceFoods.getList(null);
    }
    @RequestMapping("/getFoodsByType")
    public List<Foods> getFoodsByType(HttpServletRequest request, HttpServletResponse response){
        return serviceFoods.getList(request.getParameterMap());
    }
    @RequestMapping("/save")
    public boolean save(@RequestParam("entity") Foods entity){
        return serviceFoods.saveOrUpdate(entity);
    }
    @PostMapping("/add")
    public String add(@RequestBody() FoodDTO foodDTO){
        return serviceFoods.add(foodDTO);
    }
}

